// pages/patient/nurseinfo/nurseinfo.js
var api = require("../../../config/api.js");
var utils = require("../../../utils/util.js");
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    theme:"护士信息",
    infos: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setScrollHeight();
    this.loadNurseInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 设置scroll view的高度
  setScrollHeight: function(){
    let that = this;
    wx.getSystemInfo({
      success: function(res){
        let windowHeight = res.windowHeight;
        let screenHeight = res.screenHeight;
        console.log("windowHeight = " + windowHeight);
        console.log("screenHeight = " + screenHeight);
        let componentWrap = wx.createSelectorQuery();
        componentWrap.select('#complication').boundingClientRect();
        let complicationHeight = 0;
        componentWrap.exec(function (res) {
          console.log("complication height = " + res[0].height);
          complicationHeight = res[0].height;
          var temp = windowHeight - complicationHeight;
          console.log("scroll height = " + temp );
          that.setData({
            scrollHeight: temp
          });
        });
      }
    });
  },

  loadNurseInfo: function(){
    let that = this;
    utils.request(api.getNurseInfo, {
      id: app.globalData.myNurseId
    }).then(function(res){
      console.log("loadNurseInfo= " + JSON.stringify(res));
      if(res.errno == 0){
        var temp = res.data;
        var info = [
          {
            name: '姓名',
            type: 'text',
            value: temp.name
          },
          {
            name: '性别',
            type: 'text',
            value: temp.sex == 0? '男':'女'
          },
          {
            name: '手机号',
            type: 'text',
            value: temp.phone
          },
          {
            name: '工号',
            type: 'text',
            value: temp.jobNumber
          },
          {
            name: '科室',
            type: 'text',
            value: temp.department
          }
          
        ];
        that.setData({
          infos: info
        });
      }
    });
  }
})